using Blog2025.Application.Configurations;
using Blog2025.Application.Contracts.Configuration;
using Blog2025.Application.Services;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace Blog2025.Application;

public static class ServiceCollectionExtenstion
{
    public static IServiceCollection AddApplication(this IServiceCollection service,IConfiguration config)
    {
        service.AddScoped(typeof(AuthService));
        // 注册 MediatR
        service.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(typeof(ServiceCollectionExtenstion).Assembly));
        
        // 注册接口
        service.AddScoped<IUserAppServices,UserAppServices>();
        service.AddScoped<IRoleAppServices,RoleAppServices>();
        service.AddScoped<IDepartmentAppServices,DepartmentAppServices>();
        service.AddScoped<IPermissionAppServices,PermissionAppServices>();
        service.AddScoped<IFileUploadService, FileUploadService>();

         // 注册 JwtSettings 配置，供后续服务通过 IOptions<JwtSettings> 注入
        service.Configure<JwtSettings>(config.GetSection("Jwt"));

        // 注册 FileUploadSettings 配置
        service.Configure<FileUploadSettings>(config.GetSection("FileUpload"));

        return service;
    }
}